package com.keymozy.controller;

import com.keymozy.pojo.Borrow;
import com.keymozy.service.impl.IBorrowService;
import com.keymozy.state.Code;
import com.keymozy.state.RespData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/borrow")
@CrossOrigin
public class BorrowController {
    @Autowired
    private IBorrowService iBorrowService;
    @PostMapping("/{id}/{day}/{cost}")
    public RespData borrowModel(@PathVariable("id")Integer id,
                                @PathVariable("day")Integer day,
                                @PathVariable("cost")Integer cost){
       return new RespData(Code.SUCCESS_ADD_1,iBorrowService.borrowModel(id,day,cost));
    }
    @PostMapping("/{current}/{size}")
    public RespData borrowList(@PathVariable("current")Integer current,
                               @PathVariable("size")Integer size,
                               @RequestBody(required = false) Borrow borrow){
        Map<String, Object> map = iBorrowService.borrowList(current, size, borrow);
        return new RespData(Code.SUCCESS_SEARCH,map);
    }
}
